package com.neusoft.yuejian_01.activity;

import android.content.Intent;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;

import com.neusoft.yuejian_01.R;
import com.neusoft.yuejian_01.adapter.ProfessorAdapter;
import com.neusoft.yuejian_01.base.BaseActivity;
import com.neusoft.yuejian_01.javabean.ProfessorBean;
import com.neusoft.yuejian_01.listener.RetrofitListener;
import com.neusoft.yuejian_01.model.ProfessorModel;

import java.util.List;

public class ProfessorActivity extends BaseActivity implements RetrofitListener{
    private RecyclerView recyclerView;
    private ProfessorAdapter adapter;
    private ImageButton button_back;//返回按钮

      protected void initView() {
          setContentView(R.layout.activity_professor);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        button_back = (ImageButton) findViewById(R.id.button_back);
    }
     protected void initEvents() {
        button_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                intent.setClass(ProfessorActivity.this,MainActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }
     protected void initData() {
        ProfessorModel professorModel = new ProfessorModel();
        professorModel.professorlist(this);
    }
    @Override
    public void onSuccess(Object object, int flag) {
        List<ProfessorBean> professorBean = (List<ProfessorBean>) object;
        adapter = new ProfessorAdapter(ProfessorActivity.this, professorBean);
        LinearLayoutManager layoutManager = new LinearLayoutManager(ProfessorActivity.this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }
    @Override
    public void onFail() {
        Toast.makeText(this,"fail",Toast.LENGTH_LONG).show();
    }
}
